<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>回调</title>

    <!--引入Vue + axios-->
    <script src="js/plugins/vue/dist/vue.js"></script>
    <script src="js/plugins/axios/dist/axios.js"></script>
    <!--全局使用axios-->
    <script src="js/common.js"></script>
</head>
<body>
<div id="myDiv">

</div>
<script type="text/javascript">
    new Vue({
        el:"#myDiv",
        mounted(){
            //使用工具类解析url
            let url = location.href;
            let paramObj = parseUrlParams2Obj(url);
            let params = {code:paramObj.code,state:paramObj.state};
            //使用axios向后端发送请求
            this.$http.post("/login/wechat",params)
                .then(result=>{
                    result = result.data;
                    if (result.success) {
                        //如果曾经使用微信登录过则保存用户信息，免密登录
                        let {token, logininfo} = result.resultObj;
                        localStorage.setItem("token", token);
                        localStorage.setItem("logininfo",JSON.stringify(logininfo));

                        location.href = "index.html";
                    } else {
                        let binderUrl = "http://bugtracker.itsource.cn/binder.html"+result.resultObj;
                        location.href=binderUrl;
                    }
                })
                .catch(result=>{
                    alert("系统错误!");
                    console.log(result);
                })
        }
    });
</script>
</body>
</html>